<!-- 经营信息发布统计 -->
<template>
  <div>
    <HomeCard title="经营信息发布统计" isTimer headIcon="img_9" @checkedTimer="checkedTimer">
      <template v-slot:content>
        <div class="business-info">
          <div class="business-info-left">
            <div class="business-info-list">
              <div class="business-info-item" v-for="item in businessList" :key="item.id">
                <h4>{{ item.name }}</h4>
                <p>
                  <span :class="item.className">{{ item.num }}</span>
                  <span>条</span>
                </p>
                <div class="business-info-icon">
                  <img :src="item.imgUrl" />
                </div>
              </div>
            </div>
          </div>
          <div class="business-info-right">
            <HomeEcharts ref="EchartsRef" :echartsOption="echartsOption" />
          </div>
        </div>
      </template>
    </HomeCard>
  </div>
</template>

<script type="text/javascript">
import HomeCard from "@/pages/components/homeCard/index.vue";
import HomeEcharts from "@/pages/components/homeEcharts/index.vue";

import icon_6 from "../../assets/icon/icon_01 (6).png";
import icon_7 from "../../assets/icon/icon_01 (7).png";
import icon_10 from "../../assets/icon/icon_01 (10).png";

import { pubulishStatistics } from "@/api/home.js";

export default {
  name: "todo-page",
  components: {
    HomeCard,
    HomeEcharts,
  },
  data () {
    return {
      businessList: [
        {
          id: "1",
          name: "经营信发布数",
          num: '',
          imgUrl: icon_6,
          className: "business-info-top",
          key: 'publishCount'
        },
        {
          id: "2",
          name: "经营信息已接收",
          num: '',
          imgUrl: icon_7,
          className: "business-info-center",
          key: 'receiveCount'
        },
        {
          id: "3",
          name: "经营信息被拒收",
          num: '',
          imgUrl: icon_10,
          className: "business-info-bottom",
          key: 'refulseCount'
        },
      ],
      echartsOption: {
        backgroundColor: "#fff",
        legend: {
          right: 0,
          itemWidth: 20,
          itemHeight: 4,
          // itemGap: 10,
          show: true,
          data: ["信息总数", "已接收", "被拒收"],
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            lineStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(0, 255, 233,0)",
                  },
                  {
                    offset: 0.5,
                    color: "rgba(255, 255, 255,1)",
                  },
                  {
                    offset: 1,
                    color: "rgba(0, 255, 233,0)",
                  },
                ],
                global: false,
              },
            },
          },
        },
        grid: {
          top: "15%",
          left: "10%",
          right: "5%",
          bottom: "15%",
          // containLabel: true
        },
        xAxis: [
          {
            type: "category",
            axisLine: {
              show: false,
              color: "#A582EA",
            },
            axisLabel: {
              color: "#A582EA",
              width: 100,
              margin: 20,
            },
            data: []
          },
        ],

        yAxis: [
          {
            type: "value",
            min: 0,
            // max: 140,
            splitNumber: 4,
            splitLine: {
              show: true,
              lineStyle: {
                color: "#00BFF3",
                opacity: 0.23,
              },
            },
            axisLine: {
              show: false,
            },
            axisLabel: {
              show: true,
              margin: 20,
              textStyle: {
                color: "#333",
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        dataZoom: [
          {
            type: "slider",
            show: true,
            xAxisIndex: [0],//表示x轴折叠
            height: 8,
            width: "50%",
            left: "center",
            showDetail: false,
            startValue: 0,
            endValue: 10,
            bottom: '0'
          },
        ],
        series: [
          {
            name: "信息总数",
            type: "bar",
            barWidth: 10,
            itemStyle: {
              color: "#A582EA",
            },
            data: []
          },
          {
            name: "已接收",
            type: "bar",
            barWidth: 10,
            itemStyle: {
              color: "#f6ca9d",
            },
            data: []
          },
          {
            name: "被拒收",
            type: "bar",
            barWidth: 10,
            itemStyle: {
              color: "#2d8cf0",
            },
            data: []
          },
        ],
      },
      dimension: 'Day',
      orgId: ''
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    checkedTimer (item) {
      this.dimension = item === '年' ? 'Year' : item === '月' ? 'Month' : 'Day'
      this.init()
    },
    setOrgId (orgId = '') {
      this.orgId = orgId
      this.init()
    },
    async init () {
      const request = {
        orgId: this.orgId,
        dimension: this.dimension
      }
      const obj = await pubulishStatistics(request)

      this.businessList.forEach(it => {
        it.num = obj[it.key]
      })

      this.echartsOption.xAxis[0].data = obj.statisticsList.map(it => it.countDate)
      this.echartsOption.series[0].data = obj.statisticsList.map(it => it.publishCount)
      this.echartsOption.series[1].data = obj.statisticsList.map(it => it.receiveCount)
      this.echartsOption.series[2].data = obj.statisticsList.map(it => it.refulseCount)

      const len = obj.statisticsList.length
      this.echartsOption.dataZoom[0].startValue = len < 10 ? 0 : len - 10
      this.echartsOption.dataZoom[0].endValue = len < 10 ? 10 : len

      this.$refs.EchartsRef.handleSetVisitChart();
    }
  }
};
</script>

<style lang="less" scoped>
.business-info {
  display: flex;
}
.business-info-left {
  flex: none;
  padding: 0px 20px;
}

.business-info-item {
  position: relative;
  padding-left: 72px;
  margin-top: 20px;
  .business-info-icon {
    width: 54px;
    height: 54px;
    position: absolute;
    left: 0;
    top: 0;
    img {
      width: 100%;
    }
  }
  h4 {
    font-size: 16px;
    line-height: 24px;
    height: 24px;
  }
  p {
    height: 48px;
    span:nth-child(1) {
      font-size: 32px;
      font-weight: bold;
    }
    span:nth-child(2) {
      font-size: 14px;
      color: #888;
      margin-left: 5px;
    }
  }
}
.business-info-right {
  margin: 18px 0 0 15px;
  width: 100%;
  height: 273px;
  background: #f2f2f2;
}
.business-info-top {
  color: #0052d9;
}
.business-info-center {
  color: #1ccad5;
}
.business-info-bottom {
  color: #f45f6d;
}
</style>
